package com.action;

import com.entity.Muscle;
import com.service.MuscleService;
import com.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.List;


@Controller
@Scope("prototype")
public class MuscleAction extends BaseAction
{

    @Autowired
    private MuscleService muscleService;

    private Muscle muscle;
    private PageBean pageBean=new PageBean();
    private Integer id;


    //作用域
    private List<Muscle> muscles = new ArrayList<Muscle>();



    public String list() 
    {
        String hql="from Muscle where 1=1 ";
        String hqlCount="select count(*) from Muscle where 1=1 ";
        pageBean.setTotalCount(muscleService.getCount(hqlCount));
        muscles = muscleService.getAll(hql,pageBean.pageNo,pageBean.pageSize);
        return "muscle";
    }

    public String add()
    {
        muscleService.addMuscle(muscle);
        return "list";
    }

    public String toupdate()
    {
        muscle =muscleService.getMuscleById(id);
        return SUCCESS;
    }

    public String doupdate()
    {
        muscleService.updateMuscle(muscle);
        return "list";
    }

    public String delete()
    {
        muscleService.delById(id);
        return "list";
    }




    public MuscleService getMuscleService() 
    {
        return muscleService;
    }

    public void setMuscleService(MuscleService muscleService) 
    {
        this.muscleService = muscleService;
    }

    public Muscle getMuscle() 
    {
        return muscle;
    }

    public void setMuscle(Muscle muscle) 
    {
        this.muscle = muscle;
    }

    public PageBean getPageBean() 
    {
        return pageBean;
    }

    public void setPageBean(PageBean pageBean) 
    {
        this.pageBean = pageBean;
    }

    public Integer getId() 
    {
        return id;
    }

    public void setId(Integer id) 
    {
        this.id = id;
    }

    public List<Muscle> getMuscles() 
    {
        return muscles;
    }

    public void setMuscles(List<Muscle> muscles) 
    {
        this.muscles = muscles;
    }
}
